home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.constraints;
-
- import sub_arctic.lib.interactor;
- import sub_arctic.lib.manager;
- import sub_arctic.lib.sub_arctic_error;
-
- import java.util.Vector;
-
- /**
- * Constraint implementation class to provide encoding for standard 0 operand
- * lightweight constraints (constraint with only implicit operands). This
- * object takes a signed 16 bit value to provide a constant to the function.<p>
- *
- * 0 operand constraints are encoded as:
- * <pre>
- * 16 6 5 5
- * KKKKKKKKKKKKKKKK XXXXXX 00000 00001 64 0 operand operations
- * [K is 16 bit signed]
- * </pre>
- * where KKK represents a 16 bit signed constant, and XXX represents bits
- * used to encode an op code.<p>
- *
- * @author Scott Hudson
- */
- public class op0_impl implements std_encoding_consts {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Create a standard constraint given an op code and constant.<p>
- *
- * @param int op_code op code value for this operation.
- * @param short K value for 16 bit signed constant
- */
- public static std_constraint create(int op_code, short K)
- {
- return new std_constraint(encode(op_code,K), 0);
- }
-
- //had:
- //* @exception bad_constraint if the given op_code is out of range
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Do an encoding given an op code and constant.<p>
- *
- * @param int op_code op code value for this operation.
- * @param short K value for 16 bit signed constant
- */
- public static int encode(int op_code, short K)
- {
- if (op_code < OP0_MIN || op_code > OP0_MAX)
- throw new sub_arctic_error(
- "Unrecognized op code (" + op_code + ") used for 0 op constraint");
-
- return (((int)K)<<16) | ((op_code<<OP0_SHIFT) & OP0_MASK) | OP0_LOBITS;
- }
-
- //had:
- //* @exception bad_constraint if the given op_code is out of range
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Decode op_code from given encoding. Note: this assumes it is already
- * known that the given encoding is for a 0 op constraint. If that is
- * not the case results will wrong.<p>
- *
- * @param int enc the encoding for a 0-op constraint.
- * @return int the op code value for the constraint.
- */
- public static int op_code(int enc) { return (enc & OP0_MASK) >> OP0_SHIFT; }
-
- /**
- * Decode constant from given encoding. Note: this assumes it has already
- * known that the given encoding is for a 0 op constraint. If that is
- * not the case results will be wrong.<p>
- *
- * @param int enc the encoding for a 0-op constraint.
- * @return int the constant value for the constraint.
- */
- public static short const_val(int enc) { return (short)((enc>>16) & 0xffff); }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Evaluate an encoded constraint function given its constant value. We
- * assume here that it is has already been determined that the constraint
- * is a 0-op constraint. Note: we don't support OP_external or OP_NONE
- * here because this is called from the outside by external functions and
- * this is an error and/or we would get into infinite recursion. OP_external
- * and OP_NONE are handled as a special case in eval().<p>
- *
- * @param int enc the encoding from the constraint
- * @param interactor constr_obj the object being constrained
- * @param int cnst_val value of constant parameter
- * @param int orient orientation of the constraint (should be
- * HORIZONTAL or VERTICAL).
- * @return int the result of the evaluation
- */
- public static int eval_fun(
- int enc,
- interactor constr_obj,
- int cnst_val,
- int orient)
- {
- /* execute code for the encoded function */
- switch(op_code(enc))
- {
- case OP_NONE:
- /* this is an error for external (heavyweight) constraints */
- throw new sub_arctic_error("Can't have \"NONE\" coded in an " +
- "external constraint");
-
- case OP_external:
- /* this is an error here because for lightweight constraints,
- * this gets picked up in eval, and for heavyweight constraints
- * which are already external, this would be infinite recursion. */
- throw new sub_arctic_error("Can't have \"external()\" coded in an " +
- "external constraint");
-
- case OP_konst:
- return cnst_val;
-
- default:
- /* something is wrong if we get here */
- throw new sub_arctic_error("Improperly encoded constraint found in "+
- "op0_encoder.eval_fun()");
- }
- }
-
- //had:
- //* @exception bad_value if the encoding, or constrained object/part are
- //* malformed
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Evaluate an encoded constraint applied to the given part of the given
- * object. We assume here that it it has already been determined that
- * the constraint is a 0-op constraint.<p>
- *
- * @param int enc the encoding from the constraint
- * @param interactor constr_obj the object being constrained
- * @param int constr_part the part being constrained
- * @param int orient the orientation of the constraint
- * @return int the result of the evaluation
- */
- public static int eval(
- int enc,
- interactor constr_obj,
- int constr_part,
- int orient)
- {
- int cnst_val;
- provider_part_ref ext;
- Object val;
- int opcd;
-
- /* extract the constant */
- cnst_val = const_val(enc);
-
- /* execute code for the encoded function */
- opcd = op_code(enc);
-
- /* pull out none and external as special cases */
- if (opcd == OP_NONE)
- {
- /* this should have been picked out earlier but... treat as no-op */
- return constr_obj.get_part(constr_part);
- }
- else if (opcd == OP_external)
- {
- /* get the external value provider associated with the constrained
- * object and part */
- ext = constr_obj.get_external_constraint(constr_part);
-
- /* if there's no external attached we are in trouble */
- if (ext == null)
- throw new sub_arctic_error("External provider is null for " +
- "external constraint");
-
- /* get our value from the external provider */
- val = ext.obj.get_value(ext.part_num);
-
- /* if its not an integer we are in trouble */
- if (!(val instanceof Integer))
- throw new sub_arctic_error("Non-integer produced by external " +
- "constraint");
-
- /* return the value */
- return ((Integer)val).intValue();
- }
- else
- /* handle the rest normally */
- return eval_fun(enc, constr_obj, cnst_val, orient);
- }
-
- //had:
- //* @exception bad_value if the encoding, or constrained object/part are
- //* malformed
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Test whether the given encoded constraint (constraining the given
- * object) depends on the indicated object and part (expressed relative
- * to it). Here we assume that the encoding is already known to contain
- * a 0-op constraint.<p>
- *
- * @param int enc The encoding for the constraint.
- * @param interactor constr_obj The object the constraint is attached to
- * @param int test_which_obj The object we are asking about. This
- * can be one of the values OBJCODE_SELF,
- * OBJCODE_PARENT, OBJCODE_SOME_CHILD,
- * OBJCODE_PREV_SIBLING, or
- * OBJCODE_NEXT_SIBLING.
- * @param int test_which_part The part we are asking about.
- * @param int nth_child for SOME_CHILD, this provides the index
- * of the child (and is ignored otherwise).
- * @param int orient Orientation of the constraint. This
- * should be HORIZONTAL or VERTICAL.
- * @return boolean whether the given constraint depends upon the given value
- */
- public static boolean depends_on(
- int enc,
- interactor constr_obj,
- int which_obj,
- int which_part,
- int nth_child,
- int orient)
- {
- /* no operands (and currently no implicit dependencies) so we never
- * depend directly on our neighbors. */
- return false;
- }
-
- //had:
- //* @exception bad_value if one of the parameters has an unrecognized value
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Extract the set of objects/parts that a constraint depends on. This
- * produces a Vector with pairs of entries, the first being an interactor,
- * and the second being an Integer which is the part number of that
- * interactor that is depended upon.<p>
- *
- * Here we already know this is a 0 operand constraint so just do implicit
- * operands.<p>
- *
- * @param int enc encoding value for the constraint in question.
- * @param interactor constr_obj the object the constraint is attached to
- * (hence its referents are relative to).
- * @param int orient Orientation of the constraint. This
- * should be HORIZONTAL or VERTICAL.
- * @return Vector containing pairs of objects, the first being an interactor
- * which is depended upon, and the second being an Integer
- * giving the part number of the part depended upon.
- */
- public static Vector mk_depend_list(int enc, interactor constr_obj,int orient)
- {
- /* no operands so we just have implicits */
- return mk_implicit_depend_list(enc, constr_obj, orient);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Extract the set of objects/parts that a particular constraint function
- * implicitly depends on. This produces a Vector with pairs of entries, the
- * first being an interactor, and the second being an Integer which is the
- * part number of that interactor that is depended upon.<p>
- *
- * @param int enc encoding value for the constraint in question.
- * @param interactor constr_obj the object the constraint is attached to
- * (hence its referents are relative to).
- * @param int orient Orientation of the constraint. This
- * should be HORIZONTAL or VERTICAL.
- * @return Vector containing pairs of objects, the first being an interactor
- * which is depended upon, and the second being an Integer
- * giving the part number of the part depended upon.
- */
- public static Vector mk_implicit_depend_list(
- int enc, interactor constr_obj,int orient)
- {
- /* no implicit operands as of yet, so we return an empty result */
- return new Vector(1);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
-
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-